package com.zkingsoft.actions.admin.web;

import java.util.Arrays;

import javax.annotation.Resource;

import com.zkingsoft.services.web.WebNavService;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.web.WebNav;
import com.zkingsoft.authority.Authority;
import com.zkingsoft.authority.MatrixAdapter;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.util.WebUtil;
import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.pojo.AjaxResult;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zkingsoft.anotations.RemoveRequestToken;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-11-28 15:35
 */
@Controller
@RequestMapping(value = "admin/webNav")
public class WebNavController extends BaseController{

	@Resource
	private WebNavService webNavService;
	
	@Resource(name="authorityAdapter")
	private Authority  authorityAdapter;
	
	
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="WebNav_BEV";
	
	public static final String fnCode = "nav";
	public static final String search = fnCode + ":search";
	public static final String edit = fnCode + ":edit";
	public static final String del = fnCode + ":del";
	public static final String add = fnCode + ":add";
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(WebNav webNav, PaginationVO pageVo) {
		authorityAdapter.isBtnPermitted(search);
		return showList(webNavService, webNav, pageVo);
	}
   	

	
	/**
	 * 新增或者修改页面
	 */   
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(WebNav webNav) {
		if (webNav.getNavId() != null) {
	   		authorityAdapter.isBtnPermitted(edit);
	   		AjaxResult result=modify(webNavService, WebUtil.getSessionAttribute(this.BEV), webNav, "导航栏");
			WebUtil.removeSessionAttribute(BEV);
			return  result;
		} else {
			authorityAdapter.isBtnPermitted(add);
			return add(webNavService, webNav, "导航栏");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		authorityAdapter.isBtnPermitted(edit);
		WebNav webNav;
		if (id != null) {
			webNav = webNavService.findById(id);
			WebUtil.getRequest().setAttribute("obj", webNav);
			WebUtil.setSessionAttribute(BEV, webNav);
		}
		return "admin/web/nav-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		authorityAdapter.isBtnPermitted(del);
		return remove(webNavService, keys);
	}
 	
 	@RequestMapping(value = "/findById")
	public @ResponseBody AjaxResult findById(Long id) {
 		WebNav webNav = super.findById(webNavService, id);
 		WebUtil.setSessionAttribute(BEV, webNav);
		return new AjaxResult(AjaxResult.STATUS_OK, null, null, Arrays.asList(webNav), 0);
	}
 	
 	
 	
 	
	/**
	 * 查询所有的导航栏类型
	 */
	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all(WebNav webNav) {
		return new AjaxResult(AjaxResult.STATUS_OK, null, "执行成功",	webNavService.findByModel(webNav), 0);
	}
 	
}